package com.demofreemarker.controllers;

import com.demofreemarker.dto.Company;
import com.demofreemarker.service.DemoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Dev on 2016/6/1.
 */
@Controller
@RequestMapping(value="/demo")
public class demoController {

    @Resource
    private DemoService demoService;

    @RequestMapping(value="/index",method= RequestMethod.GET)
    public ModelAndView index(HttpServletRequest req, HttpServletResponse res){
        ModelAndView mv=new ModelAndView("index");
        Company company=new Company();
        company.setName("index");
        mv.addObject(company);
        return mv;
    }

    @RequestMapping(value = "/findById", method = RequestMethod.GET)
    @ResponseBody
    public Company findById(HttpServletRequest req, HttpServletResponse res, @RequestParam("id") Integer id) {

        return demoService.findById(id);
    }
}
